//package com.wgu.logging.aspect;
//
//import com.wgu.common.global.MyException;
//import com.wgu.common.utils.IPUtil;
//import com.wgu.common.utils.JsonUtils;
//import com.wgu.common.utils.RequestHolder;
//import com.wgu.common.utils.ThrowableUtil;
//import com.wgu.entity.Logs;
//import lombok.extern.slf4j.Slf4j;
//import org.aspectj.lang.JoinPoint;
//import org.aspectj.lang.ProceedingJoinPoint;
//import org.aspectj.lang.annotation.AfterThrowing;
//import org.aspectj.lang.annotation.Around;
//import org.aspectj.lang.annotation.Aspect;
//import org.aspectj.lang.annotation.Pointcut;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.stereotype.Component;
//
//import javax.servlet.http.HttpServletRequest;
//import java.util.Arrays;
//
///**
// * 日志切点
// * Created by w on 2019/4/25.
// */
//@Component
//@Aspect
//@Slf4j
//public class LogAspect {
//
//    @Autowired
//    private LogService logService;
//
//    private long currentTime = 0L;
//
//    /**
//     * 配置切入点
//     */
//    @Pointcut("@annotation(com.wgu.common.annotations.Log)")
//    public void logPointcut() {
//        // 该方法无方法体,主要为了让同类中其他方法使用此切入点
//    }
//
//    /**
//     * 配置环绕通知,使用在方法logPointcut()上注册的切入点
//     *
//     * @param joinPoint join point for advice
//     */
//    @Around("logPointcut()")
//    public Object logAround(ProceedingJoinPoint joinPoint){
//        HttpServletRequest request = RequestHolder.getHttpServletRequest();
//        log.info("【开始执行】请求地址: {}{} 请求类型：{} 请求参数：{} 位置：{}.{} ", IPUtil.getIP(request), request.getRequestURI(), request.getMethod(), Arrays.toString(joinPoint.getArgs()) ,joinPoint.getTarget().getClass().getSimpleName(), joinPoint.getSignature().getName());
//
//        Object result;
//        currentTime = System.currentTimeMillis();
//        try {
//            result = joinPoint.proceed();
//        } catch (Throwable e) {
//            throw new MyException(e.getMessage());
//        }
//        long time = System.currentTimeMillis() - currentTime;
//        Logs logs = new Logs("INFO",time);
//        logService.save(joinPoint, logs);
//
//        log.info("【结束】耗时{}ms 返回结果：{}", time, JsonUtils.beanToJson(result));
//        return result;
//    }
//
//    /**
//     * 配置异常通知
//     *
//     * @param joinPoint join point for advice
//     * @param e exception
//     */
//    @AfterThrowing(pointcut = "logPointcut()", throwing = "e")
//    public void logAfterThrowing(JoinPoint joinPoint, Throwable e) {
//        HttpServletRequest request = RequestHolder.getHttpServletRequest();
//        log.info("【开始执行】请求地址: {}{} 请求类型：{} 请求参数：{} 位置：{}.{} ", IPUtil.getIP(request), request.getRequestURI(), request.getMethod(), Arrays.toString(joinPoint.getArgs()) ,joinPoint.getTarget().getClass().getSimpleName(), joinPoint.getSignature().getName());
//        Logs log = new Logs("ERROR",System.currentTimeMillis() - currentTime);
//        log.setExceptionDetail(ThrowableUtil.getStackTrace(e));
//        logService.save((ProceedingJoinPoint)joinPoint, log);
//    }
//}
